home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / bytelib.arc / STRINGS.LIB < prev    next >
Encoding:
Text File  |  1985-12-13  |  2.3 KB  |  92 lines

  1. {$R-} { turn off range checking (if on) }
  2. {$V-} { turn off string parm length checking }
  3.  
  4. {
  5.         procedures and functions in this library
  6.  
  7.   LowToUp            converts string to uppercase
  8.   Strip              removes any leading characters
  9.   Parse              gets next word out of string
  10.   Replace            replaces all instance of one substring with another
  11.  
  12. }
  13.  
  14. type
  15.   BigStr             = string[255];
  16.   SetOfChar          = set of Char;
  17.  
  18. procedure LowToUp(var TStr : BigStr);
  19. {
  20.        purpose       converts TStr to all upper case
  21.        last update   23 Jun 85
  22. }
  23. var
  24.   Len,Indx           : Integer;
  25. begin
  26.   Len := Length(TStr);
  27.   for Indx := 1 to Len do
  28.     TStr[Indx] := UpCase(TStr[Indx])
  29. end; { of proc LowToUp }
  30.  
  31. procedure Strip(var Line : BigStr; var Len : Integer; Break : SetOfChar);
  32. {
  33.        purpose       pull out all chars in Break from start of Line
  34.        last update   09 Jul 85
  35. }
  36. var
  37.   Indx               : Integer;
  38. begin
  39.   Len := Length(Line);
  40.   if Len > 0 then begin
  41.     Indx := 0;
  42.     while (Line[Indx+1] in Break) and (Indx < Len) do
  43.       Indx := Indx + 1;
  44.     Delete(Line,1,Indx);
  45.     Len := Len - Indx;
  46.   end
  47. end; { of proc Strip }
  48.  
  49. procedure Parse(var Line,Word : BigStr; Break : SetOfChar);
  50. {
  51.        purpose       removes first word in Line and returns it in Word
  52.        last update   23 Jun 85
  53. }
  54. var
  55.   Len,Indx           : Integer;
  56. begin
  57.   Word := '';
  58.   Strip(Line,Len,Break);
  59.   if Len = 0
  60.     then Exit;
  61.   Indx := 0;
  62.   while not (Line[Indx+1] in Break) and (Indx < Len) do
  63.     Indx := Indx + 1;
  64.   Word := Copy(Line,1,Indx);
  65.   Delete(Line,1,Indx);
  66.   Strip(Line,Len,Break)
  67. end; { of proc Parse }
  68.  
  69. procedure Replace(var Target : BigStr; OldStr,NewStr : BigStr; MaxLen : Byte);
  70. {
  71.        purpose       look for all instances of OldStr and replace with NewStr
  72.        last update   09 Jul 85
  73. }
  74. var
  75.   TarLen,OldLen,IncLen,Indx
  76.                      : Integer;
  77. begin
  78.   TarLen := Length(Target);
  79.   OldLen := Length(OldStr);
  80.   IncLen := Length(NewStr) - OldLen;
  81.   Indx := Pos(OldStr,Target);
  82.   while Indx > 0 do begin
  83.     if TarLen + IncLen <= MaxLen then begin
  84.       Delete(Target,Indx,OldLen);
  85.       Insert(NewStr,Target,Indx);
  86.       TarLen := TarLen + IncLen;
  87.       Indx := Pos(OldStr,Target)
  88.     end
  89.     else Indx := 0
  90.   end
  91. end; { of proc Replace }
  92.